//场外部队单位

var courtTroop = {
	troopHolders : [],//主管大小，位置，z顺序，并可附加其它符号
	troopSprites : [],//主管颜色，方向，振动
	
	troopInfoSprites : [],

	CreateTroop : function(){
		this.troopHolders = [];
		this.troopSprites = [];
		
		for (var troopid = 0; troopid < campaign.troop.length; troopid++){
			if (campaign.troop[troopid].strength <= 0) continue;
			
			if (campaign.troop[troopid].court_force == false)
				continue;
			
			if (campaign.troop[troopid].force != showingForce)
				continue;

			var tileIndex = campaign.troop[troopid].tileIndex + tileEngine.xSize;

			this.troopHolders[troopid] = new cc.Node();
			this.troopHolders[troopid].attr( courtPanel.IndexToCoord(tileIndex) );
			courtPanel.node.addChild(this.troopHolders[troopid]);

			this.troopSprites[troopid] = CreateTroopSprite(troopid);
			SetTieEffect(this.troopSprites[troopid], campaign.troop[troopid].tieTimer);
			this.troopHolders[troopid].addChild(this.troopSprites[troopid], 2);

			var aura = CreateAuraSprite(campaign.troop[troopid].color);
			this.troopHolders[troopid].addChild(aura, 1);
			
			var troopInfoContainer = troopInfo._CreateInfoContainerSprite(campaign_ori.troop[troopid].strength);
			this.troopHolders[troopid].addChild(troopInfoContainer, 4);
			
			var troopInfoSprites = troopInfo._CreateTroopInfoSprite(campaign.troop[troopid].strength / campaign_ori.troop[troopid].strength);
			this.troopHolders[troopid].addChild(troopInfoSprites, 3);
			
			var troopMoraleSprites = troopInfo._CreateTroopMoraleSprite(campaign.troop[troopid].morale);
			this.troopHolders[troopid].addChild(troopMoraleSprites, 3);
		}
	},

	GetTileTroop : function(tileIndex, isBottomNotTop){
		var troopidArray = [];
		for (var troopid = 0; troopid < this.troopHolders.length; troopid++){
			if (this.troopHolders[troopid] == null) continue;

			var tileIndex_tmp = courtPanel.CoordToIndex({x:this.troopHolders[troopid].x,y:this.troopHolders[troopid].y});
			if (tileIndex_tmp == tileIndex){
				return troopid;
			}
		}
		return -1;
	},

	ClearTroop : function(){
		for (var troopid = 0; troopid < this.troopHolders.length; troopid++)
			this.RemoveTroop(troopid);
	},

	RemoveTroop : function(troopid){
		if (this.troopHolders[troopid] != null){
			this.troopHolders[troopid].removeFromParent();
			this.troopHolders[troopid] = null;
		}
	}
};